import 'package:flutter/cupertino.dart';
import 'package:flutter_network/dio_manager.dart';

/// @author: pengboboer
/// @createDate: 2022/1/11

/// 提供请求方法
typedef RequestProvider = dynamic Function(int page);

/// 解析数据
typedef ParseData<T> = T? Function(Response response);

class PagerOptions<T> {
  final RequestProvider requestProvider;
  final ParseData<T> parseData;

  PagerOptions({required this.requestProvider, required this.parseData});
}

class RefreshOptions<T> {
  final ValueChanged<List<T>> onGetPageData;
  final VoidCallback onFinishRefresh;
  final VoidCallback onFinishLoad;
  final ValueChanged<bool> onNoMoreData;
  final ValueChanged<String> onRefreshError;
  final ValueChanged<String> onLoadMoreError;

  /// 这个只有Refresh判断footer是否显示 "没有更多数据了使用"
  final ValueChanged<int> onCurrentPage;

  RefreshOptions(
      {required this.onGetPageData,
      required this.onFinishRefresh,
      required this.onFinishLoad,
      required this.onNoMoreData,
      required this.onRefreshError,
      required this.onLoadMoreError,
      required this.onCurrentPage});
}

abstract class BasePagerBean<T> {
  PagerBeanOptions<T> getOptions();
}

class PagerBeanOptions<T> {
  final ValueGetter<bool> isSucceed;
  final ValueGetter<String?> getMessage;

  /// 如果后台接口不返分页的结构，需要知道每页请求的size来判断还是否有数据
  final ValueGetter<int?> getRequestPageSize;
  final ValueGetter<List<T>?> getListData;

  final ValueGetter<int?> getCurrentPage;
  final ValueGetter<int?> getTotalPage;

  PagerBeanOptions(
      {required this.isSucceed,
      required this.getMessage,
      required this.getRequestPageSize,
      required this.getListData,
      required this.getCurrentPage,
      required this.getTotalPage,
      });
}
